package org.example.mq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用于汇总直播统计用户观看时长和pv,uv放进线程池进行处理，通过配置约束最大并发量，减少同时进行的统计
 */
public class CountStatisticsUtil {

    private final static transient Logger logger = LoggerFactory.getLogger(CountStatisticsUtil.class);

    /**
     * 任务执行线程池
     */
    private static DispatchThreadPool threadPool =  new DispatchThreadPool("统计");;

    /**
     * 直播过程轮询的update的相关业务放到线程池，统一调度，约束最大并行数量
     * @param runnable
     */
    public static void execute(Runnable runnable) {
        try {
            threadPool.execute(runnable);
        } catch (Exception e) {
            logger.debug("直播统计线程放进队列错误", e);
        }
    }

    public static void main(String[] args){
        for(int i = 0; i < 200; i++) {
            CountStatisticsUtil.execute(() -> {
                System.out.println("执行完成");
            });
        }
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
